package com.fusion.launchers.console;

import com.fusion.core.CoreSubsystem;
import com.fusion.core.ResourceSingelton;
import com.fusion.core.node.FriendManager;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Simple command line interface to Fusion
 * 
 * @author SwethaShivakumar 
 * Project: fusion
 * Date: Mar 16, 2009
 * URL: http://fusionwiki.co.cc
 * Mail Me At: shiva@fusionproject.co.cc
 */
public class Main {
    public Main(String args[]) throws Exception {
        System.out.println("Console starting with settings "+args[0]+"...");

        trace();

        Thread.currentThread().setName("Main program thread");

        CoreSubsystem core = new CoreSubsystem();
        core.init(ResourceSingelton.getRl(), args[0]);

        FriendManager manager = core.getFriendManager();

        System.out.println("Welcome to Fusion "+manager.getSettings().getMy().getNickname()+"!\n");

        Console c = new Console(core);

        while(true) {
            System.out.print("> ");
            String line;
            line = new BufferedReader(new InputStreamReader(System.in)).readLine();
            c.handleLine(line);
        }
    }

    public static void main(String[] args) throws Exception {
        new Main(args);
    }

    private void trace() {
//        if (T.t) {
//            try {
//                Class.forName("com.stendahls.trace.TraceWindow").loadOrCreate();
//            } catch(Exception e) {
//                e.printStackTrace();
//            }
//        }
    }
}
